#!/usr/bin/env python
# -*-coding:UTF-8 -*-
'''
@Project ：爬虫-波波老师
@File：14-xpath58二手.py
@Author ：文非
@Date：2021/3/1115:29
@Require： 需求爬取58二手房中的房源信息
'''

import requests
from lxml import etree
if __name__ == "__main__":
    # UA伪装
    headers = {
        'User-Agent': "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"
    }
    # 配置url
    url = "https://wh.58.com/ershoufang"
    # 发送get请求 获取响应数据
    page = requests.get(url=url, headers=headers).text # 先获取整个页面的数据
    # 实例化etree对象
    tree = etree.HTML(page)
    list_data = tree.xpath('//div[@class="property"]//h3/text()')
    # print(list_data)
    fp = open("./58ershou.txt","w",encoding="utf-8")
    for list in list_data:
        title = list
        print(title)
        fp.write(title+"\n")
    print("************* 爬取 结束 **************")



